package com.heihei.transvideo;

import com.heihei.config.ConfigProperties;
import com.heihei.util.FileUtilF;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 *  视频文件转TS格式
 *
 * @author duanhengfei
 * 2022年06月27日 01:37:34
 */
public class TransVideo2Ts {
    public static void main(String[] args) throws IOException {
        start();
    }


    public static void start() throws IOException {
        System.out.println("请输入源文件夹：");
        File validSrcDir = FileUtilF.getValidSrcDir();
        System.out.println("请输入目标文件夹：");
        File validDesDir = FileUtilF.getValidDesDir();
        StringBuilder sb = new StringBuilder();
        for (File file : validSrcDir.listFiles()) {
            if(FileUtilF.isVideo(file)) {
                //组织命令
                //"C:/Develop/ffmpeg-n4.4-latest-win64-gpl-4.4/bin/ffmpeg" -i "长安妹妹_20220727_晚.flv" -c copy -bsf:v h264_mp4toannexb -f mpegts "长安妹妹_20220727_晚.flv.ts"
                String targetFileName = file.getName();
                if(!file.getName().toLowerCase().endsWith(".mp4")) {
                    targetFileName = file.getName() + ".mp4";
                }
                String command = "\"" + ConfigProperties.FFMPEG_HOME_DIR + "\" -i \"" + file.getAbsolutePath() + "\" -c copy -bsf:v h264_mp4toannexb -f mpegts \"" + new File(validDesDir, targetFileName).getAbsolutePath() + ".ts\"";
                System.out.println(command);
                sb.append(command).append("\r\n");
            }
        }
        sb.append("pause");
        FileSystemView fsv = FileSystemView.getFileSystemView();
        File com=fsv.getHomeDirectory();
        System.out.println(com.getPath()); //这便是桌面的具体路径
        FileUtilF.writeTxtFile(sb.toString(), new File(com, "target-trans-ts-cmd.cmd"), "GBK");
    }
}
